package adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.hospitalmanagementapp.IdModel
import com.example.hospitalmanagementapp.R

class IdCardAdapter (context: Context): RecyclerView.Adapter<IdCardAdapter.IdhHolder>() {
   lateinit var dataList: MutableList<IdModel>
   private val context:Context=context
    private lateinit var listener:(position:Int)->Unit
    fun setListener(listener:(position:Int)->Unit){
        this.listener=listener
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IdhHolder {
        return IdhHolder(LayoutInflater.from(context).inflate(R.layout.id_card_item, parent, false))
    }

    override fun onBindViewHolder(holder: IdhHolder, position: Int) {
        holder.itemsNumber.text = dataList[position].Number
        holder.itemsIDNumber.text = dataList[position].IdNumber
        holder .itemsName.text = dataList[position].IdName
        holder.itemView.setOnClickListener {
            listener(holder.adapterPosition)
        }

    }

    override fun getItemCount(): Int {
   return if (dataList==null) 0 else dataList.size
    }
    inner class IdhHolder(item: View):RecyclerView.ViewHolder(item){
        var itemsNumber: TextView = item.findViewById(R.id.text_treatment_number)
        var itemsIDNumber: TextView = item.findViewById(R.id.text_ID_number)
        var itemsName: TextView = item.findViewById(R.id.my_name)
    }
}